//Shoots a few very slow bullets

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Ghosts.png");
let SEshot1=("script\SoundEffects\shots3.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=4;
let scale=1;
let shots=0;
let oldX=0; let oldY=0;
let invincible=125;

let shoottime=rand_int(30,70);
if(startx<cx){ SetAngle(0); }
if(startx>cx){ SetAngle(180); }
SetSpeed(rand(3,5));

@Initialize{
	LoadGraphic("\script\Images\Enemies\Ghosts.png");
	LoadSE("script\SoundEffects\shots3.wav");

	SetInvincibility(0);
	SetLife(5);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);

if(GetCommonData("Difficulty")==1){
	if(GetSpeed==0 && time%20==0 && shots<1){
	CreateShot02(GetX,GetY,2,GetAngleToPlayer+rand(-50,50),-0.02,rand(0.5,0.7),74,0);
	shots++;
	PlaySE(SEshot1);
	}
} //Easy

if(GetCommonData("Difficulty")==2){
	if(GetSpeed==0 && time%15==0 && shots<3){
	CreateShot02(GetX,GetY,2,GetAngleToPlayer+rand(-50,50),-0.02,rand(0.5,0.7),74,0);
	shots++;
	PlaySE(SEshot1);
	}
} //Normal

if(GetCommonData("Difficulty")==3){
	if(GetSpeed==0 && time%12==0 && shots<5){
	CreateShot02(GetX,GetY,2,GetAngleToPlayer+rand(-50,50),-0.02,rand(0.5,0.7),74,0);
	shots++;
	PlaySE(SEshot1);
	}
} //Hard

if(GetCommonData("Difficulty")==4){
	if(GetSpeed==0 && time%10==0 && shots<10){
	CreateShot02(GetX,GetY,2,GetAngleToPlayer+rand(-50,50),-0.02,rand(0.5,0.7),74,0);
	shots++;
	PlaySE(SEshot1);
	}
} //Lunatic
} //Onscreen


if(time>=30 && shots==0){ if(GetSpeed>0){ SetSpeed(GetSpeed-0.1); } if(GetSpeed<0){ SetSpeed(0); } }
if(time>=150){ if(GetSpeed<4){ SetSpeed(GetSpeed+0.1); } }



oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
let side=0;
	SetTexture(GRenemy);
		if(oldX<GetX || oldX>GetX){ side=32; }
		SetGraphicRect(256+side,212,288+side,244);
	SetGraphicAngle(0,0,0);
	if(oldX<GetX){ SetGraphicAngle(180,0,0); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
let random=rand_int(0,2);
	if(random==0){ CreateEnemyFromFile("script\Functions\itemscore.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
	if(random==1){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-50,50),GetY+rand(-50,50),0,0,0); }
if(GetCommonData("Difficulty")>1){ CreateShot02(GetX,GetY,2,GetAngleToPlayer+rand(-50,50),-0.02,rand(0.5,0.7),73,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}